package com.ztesoft.sca.dao;

import com.ztesoft.sca.model.AudioSourceDto;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author hxz
 */
@Component
public class ThreadManageDaoImpl implements com.ztesoft.sca.dao.ThreadManageDao {

    private JdbcTemplate jdbcTemplate;

    @Autowired
    public ThreadManageDaoImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
    
    @Override
    public Map<String,Object>  qryOsPublic(String stype,String pname) throws Exception {

    	List qryList=new ArrayList();
    	StringBuffer sql=new StringBuffer(" SELECT * FROM OS_PUBLIC WHERE 1=1 ");

    	if(stype!=null && !"".equals(stype)){
            sql.append("AND STYPE=? ");
            qryList.add(stype);
        }

        if (pname!=null && !"".equals(pname)){
            sql.append("AND PNAME=? ");
            qryList.add(pname);
        }

        Map<String, Object> map = this.jdbcTemplate.queryForMap(sql.toString(),qryList.toArray());
        return map;
    }






    @Override
    public void insertScaAudioSource(AudioSourceDto audioSourceDto) throws Exception {
        StringBuffer sql=new StringBuffer(" INSERT INTO SCA_AUDIO_SOURCE ")
                .append( "(file_id, file_name, file_path, server_ip, server_name, server_password, format," )
                .append(" sample_rate, descpiption, create_time ,request_action, status, call_time, book_time, book_end_time, " )
                .append(" handup_time, handup_end_time, order_status, order_id) ")
                .append(" values(SCA_AUDIO_SOURCE_SEQ.NEXTVAL,?,?,?,?,?,?,?,?,SYSDATE,?,?,?,?,?,?,?,?,?) ");

        Object[] param = new Object[]{audioSourceDto.getFileName(),audioSourceDto.getFilePath(),audioSourceDto.getServerIp(),
                audioSourceDto.getServerName(),audioSourceDto.getServerPassword(),audioSourceDto.getFormat(),
                audioSourceDto.getSampleRate(),audioSourceDto.getDescpiption(),
                audioSourceDto.getRequestAction(),audioSourceDto.getStatus(),audioSourceDto.getCallTime(),
                audioSourceDto.getBookTime(),audioSourceDto.getBookEndTime(),audioSourceDto.getHandupTime(),
                audioSourceDto.getHandupEndTime(),audioSourceDto.getOrderStatus(),audioSourceDto.getOrderId()};
        this.jdbcTemplate.update(sql.toString(),param);
    }


}
